<?php

import("data.db.DbAbstractTable");
import("data.db.DbFactory");

class DbProductGroup extends DbAbstractTable {
	
	var $className = "data.logic.product.ProductGroup";
	const CLASS_NAME =  "data.logic.product.ProductGroup";
	
	//
	// SQL Table description section
	//
	const TB_TABLENAME	= "pd_group_node";
	const TB_I			= 'grpn';
	
	const TB_NAME		= 'grpn_name';
	const TB_KIND		= 'grpn_kind';
	const TB_PARENT		= 'grpn_parent';
	
	function _get_TABLENAME() {return self::TB_TABLENAME;}
	function _get_ID() {return self::TB_I."_id";}
	function _get_SUFFIX() {return self::TB_I;}
	//
	//
	
	// properties
	var $name;
	var $kind;
	var $parent;
	
	public function __construct($noinit=false) {
		parent::__construct($noinit);
	}
	
	function getDisplayName() {
		return $this->lingvo->getValue($this->name);
	}
	
	function getName() {
		return $this->name;
	}
	function setName($name) {
		$this->name = $name;
	}
	
	function getKind() {
		return $this->kind;
	}
	function setKind($kind) {
		$this->kind = $kind;
	}
	
	function getParent() {
		return $this->parent;
	}
	function setParent($id) {
		$this->parent = $id;
	}
	
	// restore
	function fillEntity($arrResult) {
		parent::fillEntity($arrResult);
		$this->setName($arrResult[self::TB_NAME]);
		$this->setKind($arrResult[self::TB_KIND]);
		$this->setParent($arrResult[self::TB_PARENT]);
		
		//Forward Foreigns
		//$this->initForeign($arrResult, 'data.logic.catalog.LCategory');
		//$this->initForeign($arrResult, 'data.logic.user.LUser');
	}
	
	//store
	function fillFields() {
		parent::fillFields();
		$this->fildsForStore[self::TB_NAME] = "'".$this->getName()."'";
		$this->fildsForStore[self::TB_KIND] = "'".$this->getKind()."'";
		$this->fildsForStore[self::TB_PARENT] = "'".$this->getParent()."'";
		
		//$this->fildsAddForeign('data.logic.catalog.LCategory');
		//$this->fildsAddForeign('data.logic.user.LUser');
	}
	
	// static find
	function findAllByParentId($id) {
		return parent::__selectAllByCriteria(
			self::TB_PARENT."='".$id."' and ".self::_get_ID()."<>'".$id."'",
			'data.logic.product.ProductGroup');
	}
	
	// same for all classes
	public static function findAll() {return parent::findAll(self::CLASS_NAME);}
    public static function findById($id) {return parent::findById($id, self::CLASS_NAME);}
	
}
?>